<?php

/**
 * JingYao-backend
 *
 * @link     https://gitee.com/wang-zhihui-release/jingyao-backend
 * @apiDocument https://gitee.com/wang-zhihui-release/jingyao-backend/wikis/
 */

namespace App\Http\Controllers;

use App\Services\AdminLetterService;
use Illuminate\Http\Request;

class AdminLetterController extends Controller
{
    protected $adminLetterService;

    public function __construct(AdminLetterService $adminLetterService)
    {
        $this->adminLetterService = $adminLetterService;
    }

    public function getMyLetters(Request $request)
    {
        $page = $request->input('page', 1);
        $pageSize = $request->input('page_size', 100);
        $adminUserId = $request->input('user_id');
        $search = [];
        if (! is_null($request->input('is_read'))) {
            $search['is_read'] = $request->input('is_read');
        }
        $res = $this->adminLetterService->getAdminLetters($adminUserId, $page, $pageSize, $search);

        return renderSuccessJson($res);
    }

    public function makeReaded(Request $request)
    {
        $id = $request->input('id');
        $adminUserId = $request->input('user_id');
        $this->adminLetterService->makeReaded($id, $adminUserId);
        return renderSuccessJson();
    }

    public function makeAllReaded(Request $request)
    {
        $adminUserId = $request->input('user_id');
        $this->adminLetterService->makeAllReaded($adminUserId);
        return renderSuccessJson();
    }

    public function checkHaveLetterNotRead(Request $request)
    {
        $adminUserId = $request->input('user_id');
        $res = $this->adminLetterService->checkHaveLetterNotRead($adminUserId);
        return renderSuccessJson($res);
    }

    public function checkHaveLetterGroupType(Request $request)
    {
        $adminUserId = $request->input('user_id');
        $res = $this->adminLetterService->checkHaveLetterGroupType($adminUserId);
        return renderSuccessJson($res);
    }

    public function makeReadedByType(Request $request)
    {
        $adminUserId = $request->input('user_id');
        $type = $request->input('type');
        $this->adminLetterService->makeReadedByType($adminUserId, $type);
        return renderSuccessJson();
    }

    public function delete(Request $request)
    {
        $id = $request->input('id');
        $adminUserId = $request->input('user_id');
        $this->adminLetterService->delete($adminUserId, $id);
        return renderSuccessJson();
    }
}
